package org.example.controller;


import org.example.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

/*
* author: 熊义磊
* */
@WebServlet("/user_delete.action")
public class UserDeleteController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String id= request.getParameter("id");
        UserService userService = UserService.getInstance();
        int row =userService.deleteUser(id);
        if(row>0){
            response.sendRedirect("./user_list.action");
        }else {
            request.setAttribute("deleteErr", "删除失败");
            request.getRequestDispatcher("user_list.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

}
